package com.dl.mall.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.dl.mall.annotation.MethodInfo;
import com.dl.mall.annotation.SaAdminCheckRole;
import com.dl.mall.entity.Page;
import com.dl.mall.entity.user.Order;
import com.dl.mall.entity.vo.HistoryOrderVo;
import com.dl.mall.service.admin.OrderService_admin;
import com.dl.mall.utils.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author DL
 * @create 2022-04-16 14:43
 */
@Slf4j
@RestController()
@RequestMapping("/admin/order")
@SaAdminCheckRole(value = {"super","admin"})
@Api(tags="管理员订单controller")
public class OrderController_Admin {

    @Resource
    private OrderService_admin orderServiceAdmin;

    @ApiOperation(value="根据 条件 获得历史订单")
    @MethodInfo
    @PostMapping("/allHistory")
    public Result getAllHistoryOrderInfo(@RequestBody JSONObject jsonObject){
        Page<HistoryOrderVo> page = orderServiceAdmin.getHistoryOrderInfoByCondition(jsonObject);

        if (page != null){
            return Result.ok("查询历史订单成功").data("page", page);
        }else {
            return Result.error("查询历史订单失败");
        }
    }

    @ApiOperation(value="根据 订单id 获得订单详细信息")
    @MethodInfo
    @GetMapping("/orderDetail")
    public Result getOrderInfoById(String orderId){
        List<Object> result = orderServiceAdmin.getOrderInfoById(orderId);
        System.out.println("result = " + result);

        if (result != null){
            return Result.ok("查询成功").data("orderInfo", result.get(0)).data("address",result.get(1));
        }else {
            return Result.error("查询失败");
        }
    }

    @ApiOperation(value="获得最新十条")
    @MethodInfo
    @GetMapping("/orderList")
    public Result orderList(){
        List<Order> orderList = orderServiceAdmin.getOrderList();

        if (orderList != null){
            return Result.ok("查询成功").data("orderList", orderList);
        }else {
            return Result.error("查询失败");
        }
    }
}
